package com.example.demopassvalue.controller;


import com.example.demopassvalue.entity.User;
import com.example.demopassvalue.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "*")
@Slf4j
public class UserController {

    //post传值

    @PostMapping("/postUserInfo")
    public Result postUserInfo(@RequestBody User user) {
        String username = user.getUsername();
        int age = user.getAge();
        log.info("接收到的信息：用户名：{},年龄：{}", username, age);
        return Result.message("success");
    }

    @PostMapping("/postFormUserInfo")
    public Result postFormUserInfo(@RequestParam("username") String username, int age) {
        log.info("接收到的信息：用户名：{},年龄：{}", username, age);
        return Result.message("success");
    }


    @PostMapping("/postFormUserModel")
    public Result postFormUserModel(User user) {
        log.info("接收到的信息：用户名：{},年龄：{}", user.getUsername(), user.getAge());
        for (MultipartFile file : user.getFiles()) {
            System.out.println(file.getOriginalFilename());
        }
        return Result.message("success");
    }


    @GetMapping("/{username}/{age}")
    public Result getPath(@PathVariable int age, @PathVariable String username) {
        log.info("接收到的信息：用户名：{},年龄：{}", username, age);
        return Result.message("success");
    }

    @GetMapping("/getQuery")
    public Result getQuery(@RequestParam("age") int age, String username) {
        log.info("接收到的信息：用户名：{},年龄：{}", username, age);
        return Result.message("success");
    }


}
